package com.hamilton.erik.pt.core.util;

public class StringUtil {

	private static StringUtil instance = null;
	
	public static StringUtil getInstance() {
		if(instance == null) {
			instance = new StringUtil();
		}
		
		return instance;
	}

	private StringUtil() {}
	
	public static boolean isNullOrEmpty(String string) {
		return (string == null || string.isEmpty());
	}
	
	public static String capitalizeFirstLetter(String string) {
		if(!isNullOrEmpty(string)) {
			StringBuilder result = new StringBuilder(
									string.substring(0,1).toUpperCase());
			result.append(string.substring(1).toLowerCase());
			
			string = result.toString();
		}
		
		return string;
	}
	
	public static String safeDoubleToString(Double value) {
		String result = null;
		if(value != null) {
			try {
				result = Double.toString(value);
			} catch (Exception ignore) {}
		}
		
		return result;
	}
	
	public static String safeLongToString(Long value) {
		String result = null;
		if(value != null) {
			try {
				result = Long.toString(value);
			} catch (Exception ignore) {}
		}
		
		return result;
	}
}
